﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SpotsHub.Tools.MassUploader.Forms
{
    public partial class ChooseStore : Form
    {
        public int SelectedStoreId { get; set; }

        public ChooseStore()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(textBox1.Text))
            {
                var stores = DataAdapter.Instance.GetStoreByName(textBox1.Text);
                if (stores != null)
                {
                    var sis = stores.Select(s => new StoreInfo() { Id = s.Id, Name = s.Name }).ToList();
                    comboBox1.DataSource = sis;
                }
                button2.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                var s = comboBox1.SelectedItem as StoreInfo;
                SelectedStoreId = s.Id;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }

        private void ChooseStore_Load(object sender, EventArgs e)
        {
            button2.Enabled = false;
            SelectedStoreId = 0;
        }
    }
}
